<html>
<head>
<meta charset="UTF-8">
<title>Proxy - KBEngine base</title>
<link href="../../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align=left style="background:#708090"> <font size=15 color=#ffffff> KBEngine </font></td></tr>
</table> <hr>
<h1>Proxy class</h1>
<p style="text-align: center;"><span class="module_h1">[<a href="../Modules/KBEngine.html" class="module_h1">KBEngine module</a>]</span></p>
<p>Proxy is part of the <a href="../Modules/KBEngine.html">KBEngine</a> module. <a href="#detailed_description">More...</a></p><p></p><pre>import KBEngine</pre>
<h2>Parent</h2>
<a href="Entity.html">Entity</a>
<br>

<h2><a href="#" onClick="obj=document.getElementById( 'functions' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Member function</a></h2>
<table id="functions" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#disconnect" class="function_list" >disconnect</a>( self ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getClientType" class="function_list" >getClientType</a>( self ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getClientDatas" class="function_list" >getClientDatas</a>( self ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#giveClientTo" class="function_list" >giveClientTo</a>( self, proxy ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#streamFileToClient" class="function_list" >streamFileToClient</a>( self, resourceName, desc="", id=-1 ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#streamStringToClient" class="function_list" >streamStringToClient</a>( self, data, desc="", id=-1 ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'callbacks' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Callbacks</a></h2>
<table id="callbacks" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#onClientDeath" class="function_list" >onClientDeath</a>( self ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onClientGetCell" class="function_list" >onClientGetCell</a>( self ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onClientEnabled" class="function_list" >onClientEnabled</a>( self ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onGiveClientToFailure" class="function_list" >onGiveClientToFailure</a>( self ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onLogOnAttempt" class="function_list" >onLogOnAttempt</a>( self, ip, port, password ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onStreamComplete" class="function_list" >onStreamComplete</a>( self, id, success ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'attributes' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Attributes</a></h2>
<table id="attributes" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><a href="#__ACCOUNT_NAME__" class="attribute_list" >__ACCOUNT_NAME__</a></td><td>&nbsp; Read-only <a href="STRING.html">string</a></td></tr>

<tr valign=top><td><a href="#__ACCOUNT_PASSWORD__" class="attribute_list" >__ACCOUNT_PASSWORD__</a></td><td>&nbsp; Read-only <a href="STRING.html">string</a></td></tr>

<tr valign=top><td><a href="#clientAddr" class="attribute_list" >clientAddr</a></td><td>&nbsp; Read-only </td></tr>

<tr valign=top><td><a href="#clientEnabled" class="attribute_list" >clientEnabled</a></td><td>&nbsp; Read-only <a href="BOOL.html">bool</a></td></tr>

<tr valign=top><td><a href="#hasClient" class="attribute_list" >hasClient</a></td><td>&nbsp; Read-only <a href="BOOL.html">bool</a></td></tr>

<tr valign=top><td><a href="#roundTripTime" class="attribute_list" >roundTripTime</a></td><td>&nbsp; Read-only</td></tr>

<tr valign=top><td><a href="#timeSinceHeardFromClient" class="attribute_list" >timeSinceHeardFromClient</a></td><td>&nbsp; Read-only</td></tr>

</table>

<hr>
<a name="detailed_description"></a><h2>A detailed description</h2>
A <a href="Proxy.html">Proxy</a> is a special type of <a href="Entity.html">Entity</a>. 
It inherits from <a href="Entity.html">Entity</a> and has an associated client. By itself, it is a 
proxy client entity that handles all server-to-client updates. Cannot 
create <a href="Proxy.html">Proxy</a> class objects directly script.

<hr>
<h2>Member functions documentation</h2>

<a name="disconnect"></a><p class="function_definition">
<span class="function_definition">def disconnect( <i>self</i> ):</span>
</p>

<div class="function_description">
Disconnect the client.
</div>



<a name="getClientType"></a><p class="function_definition">
<span class="function_definition">def getClientType( <i>self</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function returns the client type.
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
UNKNOWN_CLIENT_COMPONENT_TYPE	= 0,<br/>
CLIENT_TYPE_MOBILE				= 1,	// Mobile phone<br/>
CLIENT_TYPE_WIN					= 2,	// PC, typically EXE clients<br/>
CLIENT_TYPE_LINUX				= 3		// Linux Application program<br/>
CLIENT_TYPE_MAC					= 4		// Mac Application program<br/>
CLIENT_TYPE_BROWSER				= 5,	// Web applications, HTML5, Flash<br/>
CLIENT_TYPE_BOTS				= 6,	// bots<br/>
CLIENT_TYPE_MINI				= 7,	// Mini-Client<br/>
CLIENT_TYPE_END					= 8		// end<br/>
</td></tr>
</table>
</p>



<a name="getClientDatas"></a><p class="function_definition">
<span class="function_definition">def getClientDatas( <i>self</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function returns the data attached to the client when logging in and 
registering.<br>
This data can be used to expand the operating system. If a third-party 
account service is connected, this data is sent to the third-party service 
system through the interfaces process.
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
tuple, a tuple of 2 elements (login data bytes, registration data bytes), 
the first element is the datas parameter passed in when the client invokes 
the login, and the second element is passed in when the client registers. 
Since they can store arbitrary binary data, they all exist as bytes.
</td></tr>
</table>
</p>



<a name="giveClientTo"></a><p class="function_definition">
<span class="function_definition">def giveClientTo( <i>self, proxy</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The client's controller is transferred to another Proxy, the current Proxy 
must have a client and the target Proxy must have no associated client, 
otherwise it will cause an error.
</div>

<p>
<span class="function_links"><b>See also:</b></span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td><a href="Proxy.html">Proxy</a>.<a href="Proxy.html#onGiveClientToFailure">onGiveClientToFailure</a><br></td></tr>
</table>
</p>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>proxy</i></span></td><td><span class="function_parameter_description">
Control will be transferred to this entity.
</span></td></tr>

</table>
</p>

<a name="streamFileToClient"></a><p class="function_definition">
<span class="function_definition">def streamFileToClient( <i>self, resourceName, desc="", id=-1</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is similar to <a href="Proxy.html#streamStringToClient">streamStringToClient()</a> 
and sends a resource file to the client. The sending process operates 
on different threads so it does not compromise the main thread.
</div>

<p>
<span class="function_links"><b>See also:</b></span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td><a href="Proxy.html">Proxy</a>.<a href="Proxy.html#onStreamComplete">onStreamComplete</a><br></td></tr>
</table>
</p>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>resourceName</i></span></td><td><span class="function_parameter_description">
The name of the resource to send, including the path.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>desc</i></span></td><td><span class="function_parameter_description">
An optional string that describes the resource sent to the client.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>id</i></span></td><td><span class="function_parameter_description">
A 16-bit id whose value depends entirely on the caller. If the incoming 
-1 system will select an unused id in the queue. The client can make 
resource judgments based on this id.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The id associated with this download.
</td></tr>
</table>
</p>

<a name="streamStringToClient"></a><p class="function_definition">
<span class="function_definition">def streamStringToClient( <i>self, data, desc="", id=-1</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Sends some data to the client bound to the current entity. If the client 
port data is cleared, this function can only be called when the client 
binds to the entity again. The 16-bit id is entirely up to the caller. <br>
If the caller does not specify this ID then the system will allocate an unused id. The client can make resource judgments based on this id. 
<br><br>

You can define a callback function (onStreamComplete) in a Proxy-derived class. This callback function is called when all data is successfully sent to the client or when the download fails. 
<br><br>
See also:
<a href="Proxy.html">Proxy</a>.<a href=Proxy.html#onStreamComplete>onStreamComplete</a>, client <a href=../../client/classes/Entity.html>Entity</a>.<a href=../../client/classes/Entity.html#onStreamDataStarted>onStreamDataStarted</a>, 
<a href=../../client/classes/Entity.html>Entity</a>.<a href=../../client/classes/Entity.html#onStreamDataRecv>onStreamDataRecv</a>, and <a href=../../client/classes/Entity.html>Entity</a>.<a href=../../client/classes/Entity.html#onStreamDataCompleted>onStreamDataCompleted</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>data</i></span></td><td><span class="function_parameter_description">
The string to send
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>desc</i></span></td><td><span class="function_parameter_description">
An optional description string sent. 
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>id</i></span></td><td><span class="function_parameter_description">
A 16-bit id whose value depends entirely on the caller. If the incoming -1 system will select an unused id in the queue.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The id associated with this download.
</td></tr>
</table>
</p>

<hr>
<h2>Callback functions documentation</h2>


<a name="onClientDeath"></a><p class="function_definition">
<span class="function_definition">def onClientDeath( <i>self</i> ):</span>
</p>

<div class="function_description">If this callback is implemented in a script, this method will be called when the client disconnects. This method has no parameters.
</div>

<a name="onClientGetCell"></a><p class="function_definition">
<span class="function_definition">def onClientGetCell( <i>self</i> ):</span>
</p>

<div class="function_description">If this callback is implemented in a script, 
the callback is called when the client can call the entity's 
<a href=../../keywords.html#cell>cell</a> attribute
</div>

<a name="onClientEnabled"></a><p class="function_definition">
<span class="function_definition">def onClientEnabled( <i>self</i> ):</span>
</p>

<div class="function_description">If this callback is implemented in the 
script, it is invoked when the entity is available (various initializations 
and communication with the client). This method has no parameters. <br>
Note: giveClientTo also assigns control to the entity and causes the callback to be called.
</div>

<a name="onGiveClientToFailure"></a><p class="function_definition">
<span class="function_definition">def onGiveClientToFailure( <i>self</i> ):</span>
</p>

<div class="function_description">
If this callback is implemented in a script, it is called when the entity 
fails to call <a href=#onStreamComplete>giveClientTo</a>. 
This method has no parameters.
</div>


<a name="onLogOnAttempt"></a><p class="function_definition">
<span class="function_definition">def onLogOnAttempt( <i>self, ip, port, password</i> ):</span>
</p>

<div class="function_description">If this callback is implemented in a 
script, it is invoked when a client attempts to log in using the current 
account entity. <br>
This situation usually happens when the entity that exists in memory is in a valid 
state, the most obvious example is user A logs in with this account, 
and user B tries to use the same account to log in, triggering this callback. 
<br><br>
This callback function can return the following constant values:<br> 
<a href="../Modules/KBEngine.html">KBEngine</a>.<a href=KBEngine.html#LOG_ON_ACCEPT>LOG_ON_ACCEPT</a>: 
Allows the new client to bind to the entity. If the entity has bound a 
client, the previous client will be kicked out.<br>
<a href="../Modules/KBEngine.html">KBEngine</a>.<a href=KBEngine.html#LOG_ON_REJECT>LOG_ON_REJECT</a>: 
Reject new client entity binding.<br>
<br><a href="../Modules/KBEngine.html">KBEngine</a>.<a href=KBEngine.html#LOG_ON_WAIT_FOR_DESTROY>LOG_ON_WAIT_FOR_DESTROY</a>: 
Wait for the entity to be destroyed before the client binds.
<br><br>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>ip</i></span></td><td><span class="function_parameter_description">&nbsp; 
The IP address of the client trying to log in.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>port</i></span></td><td><span class="function_parameter_description">&nbsp; 
The port to which the client attempted to log in.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>password</i></span></td><td><span class="function_parameter_description">&nbsp; 
The MD5 password used when the user logs in.
</span></td></tr>

</table>
</p>

<a name="onStreamComplete"></a><p class="function_definition">
<span class="function_definition">def onStreamComplete( <i>self, id, success</i> ):</span>
</p>

<div class="function_description"> If you implement this callback in a 
script, when a user uses <a href="Proxy.html">Proxy</a>.<a href=Proxy.html#streamStringToClient>streamStringToClient</a>() 
or <a href="Proxy.html">Proxy</a>.<a href=Proxy.html#streamFileToClient>streamFileToClient</a>() 
and is completed, this callback is invoked.


</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>id</i></span></td><td><span class="function_parameter_description">&nbsp;
The id associated with the download.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>success</i></span></td><td><span class="function_parameter_description">&nbsp; 
Success or failure
</span></td></tr>

</table>
</p>

<hr>
<h2>Attributes documentation</h2>

<a name="__ACCOUNT_NAME__"></a><p class="attribute_definition">
<span class="attribute_definition">__ACCOUNT_NAME__</span>
</p>

<div class="attribute_description">
<b>Note:</b><br><br>
If the proxy is an account, you can access __ACCOUNT_NAME__ to get the account name.
</div>

<a name="__ACCOUNT_PASSWORD__"></a><p class="attribute_definition">
<span class="attribute_definition">__ACCOUNT_PASSWORD__</span>
</p>

<div class="attribute_description">
<b>Note:</b><br><br>
If the proxy is an account, you can access __ACCOUNT_PASSWORD__ to get the MD5 password.
</div>

<a name="clientAddr"></a><p class="attribute_definition">
<span class="attribute_definition">clientAddr</span>
</p>

<div class="attribute_description">
This is a tuple object that contains the client's ip and port.
</div>

<a name="clientEnabled"></a><p class="attribute_definition">
<span class="attribute_definition">clientEnabled</span>
</p>

<div class="attribute_description">
Whether the entity is already available. The script cannot communicate with the client until the entity is available.
</div>

<a name="hasClient"></a><p class="attribute_definition">
<span class="attribute_definition">hasClient</span>
</p>

<div class="attribute_description">
Proxy is bound to a client connection.
</div>

<a name="roundTripTime"></a><p class="attribute_definition">
<span class="attribute_definition">roundTripTime</span>
</p>

<div class="attribute_description">
The average round-trip time for client communication between the server and this Proxy over a period of time. This property only takes effect under Linux.
</div>

<a name="timeSinceHeardFromClient"></a><p class="attribute_definition">
<span class="attribute_definition">timeSinceHeardFromClient</span>
</p>

<div class="attribute_description">
The time (in seconds) that has passed since the client packet was last received.
</div>

<hr>
<p class="copyrightFooter">Copyright KBEngine</p>
</body>
</html>
